public class Solution {
    public boolean VerifySquenceOfBST(int [] sequence) {
        if(sequence == null || sequence.length == 0){
            return false;
        }
        return helpVerify(sequence,0,sequence.length-1);
    }
    
    public boolean helpVerify(int[] sequence, int start, int end){
        if(start >= end) return true;
        //先定义根结点
        int root = sequence[end];
        int i;
        //找左右子树的分界点
        for(i = start; i < end; i++){
            //当遇到比根结点值大的数时，退出循环
            if(sequence[i] > root){
                break;
            }
        }
        //此时i左边的值都小于root，判断i右边是否有小于root的值，如果有返回false
        for(int j = i; j < end; j++){
            if(sequence[j] < root){
                return false;
            }
        }
        //递归分治左子树与
        return helpVerify(sequence,start,i-1) && helpVerify(sequence,i,end-1);
    }
}